package 笔试题;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/1/8
 * @description
 */
public class Demo2126摧毁小行星 {


    public boolean asteroidsDestroyed(int mass, int[] asteroids) {
        Arrays.sort(asteroids);

        if(mass< asteroids[0]){
            return false;
        }
        mass+=asteroids[0];
        for (int i = 1; i < asteroids.length; i++) {
            if(mass < asteroids[i]){
                return false;
            }
            mass+=asteroids[i];
            if(mass>100000){
                break;
            }

        }
        return true;
    }

}
